package cn.edu.neusoft.maxingxin231.yuejian06.Fragment.activityFragment;

import android.content.Context;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.List;
import cn.edu.neusoft.maxingxin231.yuejian06.Adapter.ActivityAdapter;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.ActivityBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Listener.ListListener;
import cn.edu.neusoft.maxingxin231.yuejian06.Model.ActivityModel;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class ActivityFragment extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recyclerview_activity;
    private RecyclerView.LayoutManager layoutManager;
    private ActivityAdapter activityAdapter;
    private List<ActivityBean> items=null;
    ListListener<ActivityBean>activityBeanListListener=new ListListener<ActivityBean>() {
        @Override
        public void onResponse(List<ActivityBean> list) {
            Toast.makeText(context, "success", Toast.LENGTH_SHORT).show();
            items = list;
            activityAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        view=inflater.inflate(R.layout.fragment_activity2,container,false);
        recyclerview_activity=(RecyclerView) view.findViewById(R.id.recyclerview_activity);
        layoutManager=new LinearLayoutManager(context);
        recyclerview_activity.setLayoutManager(layoutManager);
        activityAdapter=new ActivityAdapter(getActivity(),items,R.layout.club_card);
        activityAdapter.setList(items);

        recyclerview_activity.setAdapter(activityAdapter);
        ActivityModel activityModel = new ActivityModel();
        activityModel.getActivityList(activityBeanListListener);
        return view;

    }
}
